# -*- coding: utf-8 -*-
"""
简化的业态功能测试
"""

import sys
import os
sys.path.append(os.path.dirname(os.path.abspath(__file__)))

from src.crawler.business_type_manager import BusinessTypeManager, BusinessTypeStatus


def test_business_type_manager():
    """测试业态管理器基本功能"""
    print("开始测试业态管理器...")
    
    # 初始化业态管理器
    btm = BusinessTypeManager()
    print("✅ 业态管理器初始化成功")
    
    # 测试支持的业态
    supported_types = btm.get_supported_business_types()
    print(f"✅ 支持的业态: {supported_types}")
    
    # 测试业态配置
    for business_type in supported_types:
        config = btm.get_business_type_config(business_type)
        code = btm.get_business_type_code(business_type)
        display_name = btm.get_business_type_display_name(business_type)
        
        print(f"🏪 {business_type}:")
        print(f"   - 代码: {code}")
        print(f"   - 显示名称: {display_name}")
        print(f"   - 关键词: {config['keywords'][:3]}...")
    
    # 测试业态切换
    print("\n测试业态切换...")
    for business_type in supported_types:
        success = btm.switch_business_type(business_type)
        current = btm.get_current_business_type()
        print(f"✅ 切换到 {business_type}: {success}, 当前: {current}")
    
    # 测试状态管理
    print("\n测试状态管理...")
    btm.set_business_type_status('餐饮', BusinessTypeStatus.PROCESSING)
    status = btm.get_business_type_status('餐饮')
    print(f"✅ 餐饮状态设置为: {status.value}")
    
    # 测试数据验证
    print("\n测试数据验证...")
    test_data = [
        {
            'title': '寻找餐厅转让',
            'business_type': '餐饮',
            'contact_person': '张先生',
            'contact_info': '13800138000',
            'acceptable_rent': '5000元/月',
            'building_area': '100平米'
        }
    ]
    
    validation_result = btm.validate_business_type_data('餐饮', test_data)
    print(f"✅ 数据验证结果: 准确性 {validation_result['business_type_accuracy']:.1f}%")
    
    # 测试统计信息
    print("\n测试统计信息...")
    stats = btm.generate_business_type_stats()
    print(f"✅ 统计信息生成成功，处理业态数: {stats['session_summary']['total_business_types']}")
    
    print("\n🎉 业态管理器测试完成！")
    return True


if __name__ == "__main__":
    try:
        success = test_business_type_manager()
        sys.exit(0 if success else 1)
    except Exception as e:
        print(f"❌ 测试失败: {e}")
        import traceback
        traceback.print_exc()
        sys.exit(1)
